﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACP.DTO;

namespace ACP.Data
{
    public class QuestionsRepository : Repository<question>
    {
        // Add your own data access methods.
        // This file should not get overridden
        public static List<question> GetAllQuestions()
        {
            List<question> lstQuestions;
            IRepository<question> questionsRepository = new Repository<question>();
            try
            {
                lstQuestions = questionsRepository.GetAll().ToList();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                questionsRepository.Dispose();
            }
            return lstQuestions;

        }

        public static question GetQuestionById(int id)
        {
            IRepository<question> questionsRepository = new Repository<question>();
            question questionEntity;
            try
            {
                questionEntity = questionsRepository.First(q => q.questionid == id);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                questionsRepository.Dispose();
            }
            return questionEntity;
        }

        public static void UpdateQuestion(question questionObject)
        {
            Repository<question> questionsRepository = new Repository<question>();
            try
            {
                questionsRepository.Update(questionObject);
                questionsRepository.UnitOfWork.Commit();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                questionsRepository.Dispose();
            }
        }
    }
}
